home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-05 | 9.9 KB | 356 lines | [TEXT/CWIE] |
- // ----------------------------------------------------------------------
- //
- // Module:
- // IBM OEM Ethernet.c
- //
- // Purpose:
- // This enabler is designed to correct the IBM OEM Ethernet PC Card.
- // The IBM OEM Ethernet card has a 1B tuple that instructs the PC Card
- // 3.0 family to place the buffer memory at 11000 instead of 4000 where
- // it is located.
- //
- // Authors:
- // Carl Fallis
- //
- // Copyright: © 1996 SystemSoft Corporation, all rights reserved.
- // ----------------------------------------------------------------------
-
- #define FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE 1
- #define FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED 1
-
- #include <PCCardEnablerPlugin.h>
- #include <PCCardTuples.h>
- #include <Errors.h>
- #include <Devices.h>
- #include <DriverServices.h>
-
- //#define DEBUG_ON 1
- #ifdef DEBUG_ON
- #define DebugMessage(x) SysBreakStr(x)
- #else
- #define DebugMessage(x)
- #endif
-
- //----------------------------------------------------------------------
-
- #define kIBMOEMEthernet 0x0a4000200
-
- #define kManifID 0x0a400
- #define kManifInfo 0x00200
-
- const unsigned char kIBM1BBadData[] = {0xC1,0x81,0x7E,0x19,0x55,0x15,
- 0x26,0x01,0x0E,0xFC,0x33,0x45,0x70,
- 0xFF,0xFF,0x48,0x40,0x10,0x01};
-
- const unsigned char kIBM1BGoodData[] = {0xC1,0x81,0x7E,0x19,0x55,0x15,
- 0x26,0x01,0x0E,0xFC,0x33,0x45,0x70,
- 0xFF,0xFF,0x48,0x40,0x40,0x00};
-
-
- //----------------------------------------------------------------------
- // Local Prototypes
-
- typedef PCCardTupleIterator PCCardTupleIteratorPtr;
-
- OSStatus MyValidateHardware(const RegEntryID * lpCardEntry);
- OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device, PCCardTupleIteratorPtr lpTupleIterator,
- Byte desiredTuple, void *lptupleData, UInt32 *lpTupleBufferSize, Byte *lpFoundTuple);
- OSStatus MyGetNextTuple(PCCardTupleIteratorPtr tupleIterator, Byte desiredTuple, void *tupleData, ByteCount *tupleBufferSize, Byte *foundTuple);
-
-
- OSStatus _IdentifyCard(const RegEntryID * lpCardEntry);
- Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName);
-
- //----------------------------------------------------------------------
- // Globals
-
- #define kVersionMajor 1
- #define kVersionMinor 0
- #define kVersionStage developStage
- #define kVersionNonRel 1
- #define kPluginNamePString "\ppccarda4,2"
-
- #pragma export on
-
- // --------------------
- // Here's the exported Driver Descriptor
- DriverDescription TheDriverDescription = {
- /*
- * Signature info
- */
- kTheDescriptionSignature, /* OSType driverDescSignature */
- kInitialDriverDescriptor, /* DriverDescVersion driverDescVersion */
- /*
- * DriverType driverType - these are defined in
- */
- kPluginNamePString, /* Name of hardware */
- kVersionMajor, kVersionMinor, /* NumVersion version */
- kVersionStage, kVersionNonRel,
-
- /*
- * DriverOSRuntime driverOSRuntimeInfo
- */
- kDriverIsLoadedUponDiscovery | /* Loader runtime options */
- kDriverIsUnderExpertControl, /* I/O expert handles loads/opens */
- kPluginNamePString, /* Str31 driverName (OpenDriver param) */
- 0, 0, 0, 0, 0, 0, 0, 0, /* UInt32 driverDescReserved[8] */
-
- /*
- * DriverOSService Information. This section contains a vector count followed by
- * a vector of structures, each defining a driver service.
- */
- 1, /* ServiceCount nServices */
-
- /*
- * DriverServiceInfo service[0]
- */
- kServiceCategoryPCCard, /* OSType serviceCategory */
- kServiceTypePCCardEnabler, /* OSType serviceType */
-
- 1, 0,developStage, 1
- };
-
-
- // --------------------
- // Here's the exported Plugin Function Table…
- PCCardEnablerPluginDispatchTable ThePluginDispatchTable =
- {
- /* PCCardEnablerPluginHeader */
- { kPCCardEnablerPluginCurrentVersion, 0, 0, 0 },
-
- /* CEValidateHardwareProc */ MyValidateHardware,
- /* CEInitializeProc */ CEInitializeCard,
- /* CECleanupProc */ CEFinalizeCard,
- /* CEPowerManagementProc */ CEPowerManagement,
-
- /* CEHandleEventProc */ CEHandleCardEvent,
- /* CEGetCardInfoProc */ CEGetCardInfo,
- /* CEAddCardPropertiesProc */ CEAddCardProperties,
- /* CEGetDeviceCountProc */ CEGetDeviceCount,
-
- /* CEGetDeviceNameProc */ CEGetDeviceName,
- /* CEGetDeviceCompatibleNameProc */ CEGetDeviceCompatibleNames,
- /* CEGetDeviceTypeProc */ CEGetDeviceType,
- /* CEGetDeviceTypeNameProc */ CEGetDeviceTypeName,
- /* CEAddDevicePropertiesProc */ CEAddDeviceProperties,
- /* CEConfigureDeviceProc */ CEConfigureDevice,
- /* CEFinalizeDeviceProc */ CEFinalizeDevice,
-
- /* CEValidateCISProc */ CEValidateCIS,
- /* CEGetFirstTupleProc */ MyGetFirstTuple,
- /* CEGetNextTupleProc */ MyGetNextTuple,
-
- /* InterruptHandler */ CEDefaultInterruptHandler,
- /* InterruptEnabler */ NULL,
- /* InterruptDisabler */ NULL
- };
-
- #pragma export off
-
- //----------------------------------------------------------------------
- // Determine whether the plugin can support this card.
- // Returning noErr means that the card is supported
- OSStatus MyValidateHardware(const RegEntryID *lpCardEntry)
- {
- OSStatus err;
-
- // DebugStr("\pCustomCardEnabler: MyValidateHardware");
- if (!(lpCardEntry)) return(paramErr);
-
- // see if we are supposed to handle this card, set global card id
- err = _IdentifyCard(lpCardEntry);
-
- #ifdef DEBUG_ON
- if (err == noErr) DebugMessage("\pIBM OEM Ethernet Enabler will handle this card!;g");
- #endif
- return(err);
- }
-
-
- //----------------------------------------------------------------------
- // Look to see if this is a card we are supposed to handle
- // If it is return noErr, other wise return kUnsupportedCardErr
- //
- // Identification of the IBM OEM Ethernet card
- // 1) check the manufacturer's ID
- // 2) check the vers 1 for IBM Corp Ethernet
- // 3) check for the config table entry for the bad entry so that we are sure that
- // this is the correct card we say it is our card
- OSStatus _IdentifyCard(const RegEntryID *lpCardEntry)
- {
- PCCardTupleIteratorPtr iter;
- OSStatus err = noErr;
- unsigned char tuple[MAX_TUPLE_SIZE];
- UInt32 size=MAX_TUPLE_SIZE, socket, device;
- Byte foundTuple;
- Boolean match = false;
- int i=0;
-
-
- // DebugStr("\pCustomCardEnabler: _IdentifyCard");
- if(!(lpCardEntry) ) return(paramErr);
-
- err = CEGetSocketAndDeviceFromRegEntry(lpCardEntry, &socket, &device);
- if (err != noErr)
- return(err);
-
- iter = PCCardNewTupleIterator();
- if (iter == NULL)
- return memFullErr;
-
- err = CECompareCISTPL_MANFID(lpCardEntry,
- kManifID,
- kManifInfo,
- &match);
-
-
- if ((err != noErr) || (match != true))
- goto CLEAN_ERROR_EXIT;
-
- // step one passed now check the vers 1 using the built in CheckVers1Tuple call
-
- err = CSGetFirstTuple(socket, device, iter, CISTPL_VERS_1, &tuple, &size, &foundTuple);
-
- if ((err != noErr) && (foundTuple == CISTPL_VERS_1))
- goto CLEAN_ERROR_EXIT;
-
-
- if ( !CheckVers1Tuple(&tuple[0], "IBM Corp.", "Ethernet") )
- goto CLEAN_ERROR_EXIT;
-
-
- // we made it this far lets see if the touple is incoorect
- err = CSGetFirstTuple(socket, device, iter, CISTPL_CFTABLE_ENTRY, &tuple, &size, &foundTuple);
-
- if (err != noErr)
- goto CLEAN_ERROR_EXIT;
-
- // compare the Table entry with the known bad entry to make sure that this is the card
-
- match = true;
- for (i=0;i < sizeof(kIBM1BBadData); i++)
- {
- if (tuple[i] != kIBM1BBadData[i])
- {
- match = false;
- continue;
- }
- }
-
- if (match) // this is the card !
- {
- (void) PCCardDisposeTupleIterator(iter);
- return(noErr);
- }
-
-
-
-
- CLEAN_ERROR_EXIT:
-
- (void) PCCardDisposeTupleIterator(iter);
- return(kUnsupportedCardErr);
-
- }
-
-
-
-
- //----------------------------------------------------------------------
- OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device,
- PCCardTupleIteratorPtr lpTupleIterator,
- Byte desiredTuple,
- void *lpTupleData,
- UInt32 *lpTupleBufferSize,
- Byte *lpFoundTuple)
- {
- OSStatus err = noErr;
- unsigned char *dataPtr = (unsigned char *)lpTupleData;
- UInt32 i=0;
-
-
- // DebugStr("\pCustomCardEnabler: MyGetFirstTuple");
- if(!(lpTupleIterator && lpFoundTuple && lpTupleData && *lpTupleBufferSize))
- return(paramErr);
-
-
-
- err = CSGetFirstTuple(socket, device,lpTupleIterator,desiredTuple,
- lpTupleData,lpTupleBufferSize,lpFoundTuple);
-
-
-
- if (*lpFoundTuple == CISTPL_CFTABLE_ENTRY)
- {
- // for (i=0;i< *lpTupleBufferSize;i++)
- // dataPtr[i] = (unsigned char)kIBM1BGoodData[i];
- dataPtr[17] = kIBM1BGoodData[17];
- dataPtr[18] = kIBM1BGoodData[18];
- }
- return(err);
- }
-
- //
- // MyGetNextTuple
- //
- OSStatus MyGetNextTuple(PCCardTupleIteratorPtr lpTupleIterator,
- Byte desiredTuple,
- void *lpTupleData,
- ByteCount *lpTupleBufferSize,
- Byte *lpFoundTuple)
- {
- OSStatus err = noErr;
- unsigned char *dataPtr = (unsigned char *)lpTupleData;
- UInt32 i=0;
-
-
- // DebugStr("\pCustomCardEnabler: MyGetNextTuple");
- if(!(lpTupleIterator && lpFoundTuple && lpTupleData && *lpTupleBufferSize))
- return(paramErr);
-
-
-
- err = CSGetNextTuple(lpTupleIterator, desiredTuple,lpTupleData,lpTupleBufferSize,
- lpFoundTuple);
-
-
- if (*lpFoundTuple == CISTPL_CFTABLE_ENTRY)
- {
- // for (i=0;i< *lpTupleBufferSize;i++)
- // dataPtr[i] = kIBM1BGoodData[i];
-
- // change the last two bytes of the tuple to x04000
- dataPtr[17] = kIBM1BGoodData[17];
- dataPtr[18] = kIBM1BGoodData[18];
- }
- return(err);
- }
-
-
- //----------------------------------------------------------------------
- // Pass in a VERS1 tuple and check that the manufacturer name and card name are
- // the the same as the ones passed in
- Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName)
- {
- unsigned char *ptr;
-
-
- // DebugStr("\pCustomCardEnabler: CheckVers1Tuple");
- // the manufacturer name is a null terminated string starting in byte three
- ptr = &(data[2]);
- if(CStrCmp((const char *) ptr, manufacturerName) == 0)
- {
- // the card name is a null terminated string that starts after the manufacturer name
- while(*ptr++)
- ;
- if(CStrCmp((const char *) ptr, cardName) != 0)
- return(false);
- }
- else
- return(false);
-
- // if we make it to here, both names match
- return(true);
- }
-
-